package sql;

import bean.Student;
import org.apache.ibatis.jdbc.SQL;

public class ReturnSql {
    public String getSelectAll(){
      return   new SQL(){
            {
                SELECT("*");
                FROM("student");
            }
        }.toString();
    }

    public String getInsert(Student stu){
        return new SQL(){
            {
                INSERT_INTO("student");
                INTO_VALUES("#{id},#{name},#{age}");
            }
        }.toString();
    }

    public String getUpdate(Student stu){
        return new SQL(){
            {
                UPDATE("student");
                if(stu.getName()!=null){
                    SET("name=#{name}");
                }
                if(stu.getAge()!=null){
                    SET("age=#{age}");
                }
                WHERE("id=#{id}");
            }
        }.toString();
    }

    public String getDelete(Integer id){
        return new SQL(){
            {
                DELETE_FROM("student");
                WHERE("id=#{id}");
            }
        }.toString();
    }
}
